{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE UndecidableInstances #-}

module Vote.Internal.Model where

import Data.Time (UTCTime)
import Database.Persist.TH (mkMigrate, mkPersist, persistLowerCase, share, sqlSettings)
import Protolude
import Vote.Internal.Enum (enumSceneType)
import Vote.TH.Enum (makeEnum, makeEnumIns)

makeEnum enumSceneType
makeEnumIns enumSceneType

share
  [mkPersist sqlSettings, mkMigrate "migrateAll"]
  [persistLowerCase|
    Scene
      info Text
      type SceneType
      timeOpen (Maybe UTCTime)
      timeShut (Maybe UTCTime)
      markDeno Int
      deriving Show Eq Generic
    Actor
      sceneId SceneId
      info Text
      deriving Show Eq Generic
    Voter
      sceneId SceneId
      info Text
      factorNume Int
      factorDeno Int
      deriving Show Eq Generic
    Action
      sceneId SceneId
      actorId ActorId
      voterId VoterId
      markNume Int
      UniqueAction sceneId actorId voterId
      deriving Show Eq Generic
  |]
